package com.kkang.betmachine.util;

import com.kkang.betmachine.entity.LanQiuMatche;
import com.kkang.betmachine.entity.Matche;
import org.springframework.util.StringUtils;

import java.util.*;

/**
 * 注码组装
 *
 * @author yongk_liu
 **/
public class BetCodeUtil {

    private static final int MIN_TEAM_SIZE = 2;//最小比赛场次

    /**
     * 组装拆分
     *
     * @param matchList
     * @return
     */
    public static List<String> splitMixLanQiuCode(List matchList) {
        List<String> teamIds = new ArrayList<>();
        String[] J00005 = null;
        String[] J00006 = null;
        String[] J00007 = null;
        String[] J00008 = null;

        for (int i = 0; i < matchList.size(); i++) {
            LanQiuMatche o = (LanQiuMatche) matchList.get(i);
            String teamId = o.getTeamId();
            String unsport = o.getUnsport();
            J00005 = o.getJ00005();
            J00006 = o.getJ00006();
            J00007 = o.getJ00007();
            J00008 = o.getJ00008();

            if (!StringUtils.isEmpty(unsport)) {
                for (String s : unsport.split(",")) {
                    switch (s) {
                        case "J00005":
                            J00005 = new String[0];
                            break;
                        case "J00006":
                            J00006 = new String[0];
                            break;
                        case "J00007":
                            J00007 = new String[0];
                            break;
                        case "J00008":
                            J00008 = new String[0];
                            break;
                    }
                }
            }
            teamIds.add(teamId);
        }

        List<String> strs = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            appendStr(strs, teamIds, J00005, J00006, J00007, J00008);
        }
        //去重复
        List<String> newList = new ArrayList(new HashSet(strs));
        return newList;
    }

    private static void appendStr(List<String> strs, List<String> teamIds, String[] J5, String[] J6, String[] J7, String[] J8) {
        StringBuffer sb = new StringBuffer("");
        Double teamId = Math.random() * teamIds.size();
        sb.append(teamIds.get(teamId.intValue()));


        Double v = Math.random() * 3;
        switch (v.intValue()) {
            case 0:
                Double _5 = Math.random() * J5.length;
                sb.append("|J00005|" + J5[_5.intValue()] + "^");
                break;
            case 1:
                Double _6 = Math.random() * J6.length;
                sb.append("|J00006|" + J6[_6.intValue()] + "^");
                break;
            case 2:
                Double _7 = Math.random() * J7.length;
                sb.append("|J00007|" + J7[_7.intValue()] + "^");
                break;
            case 3:
                Double _8 = Math.random() * J8.length;
                sb.append("|J00008|" + J8[_8.intValue()] + "^");
                break;
        }
        strs.add(sb.toString());
    }

}
